package com.cg.mapper;

import org.apache.ibatis.annotations.*;

@Mapper
public interface JobFavoriteMapper {

    @Insert("INSERT INTO job_favorite(table_name, job_id, user_id, status) VALUES(#{table}, #{jobId}, #{userId}, 1)"
            + " ON DUPLICATE KEY UPDATE status=1, update_time=NOW()")
    int favorite(@Param("table") String table,
                 @Param("jobId") Integer jobId,
                 @Param("userId") Long userId);

    @Update("UPDATE job_favorite SET status=0, update_time=NOW() WHERE table_name=#{table} AND job_id=#{jobId} AND user_id=#{userId}")
    int unfavorite(@Param("table") String table,
                   @Param("jobId") Integer jobId,
                   @Param("userId") Long userId);

    @Select("SELECT COUNT(1) FROM job_favorite WHERE table_name=#{table} AND job_id=#{jobId} AND status=1")
    long count(@Param("table") String table,
               @Param("jobId") Integer jobId);

    @Select("SELECT status FROM job_favorite WHERE table_name=#{table} AND job_id=#{jobId} AND user_id=#{userId} LIMIT 1")
    Integer status(@Param("table") String table,
                   @Param("jobId") Integer jobId,
                   @Param("userId") Long userId);
}


